package net.hn.hnms.biz.energy.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.energy.domain.ElectricitySettlement;
import net.hn.hnms.biz.energy.request.ElectricitySettlementReq;
import net.hn.hnms.biz.energy.service.ElectricitySettlementService;
import net.hn.hnms.biz.energy.vo.ElectricitySettlementVo;
import net.hn.hnms.biz.energy.vo.ElectricitySettlementVo1;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "用电费用管理", tags = {"用电费用管理"})
@RestController
@RequestMapping("/electricity/settlement")
public class ElectricitySettlementController extends BaseController {

    @Autowired
    private ElectricitySettlementService electricitySettlementService;

    /**
     * 新增用电地点电单价设置
     */
    @ApiOperation("新增用电费用管理")
    @SaCheckPermission("electricity:settlement:add")
    @PostMapping("/add")
    @Log(title = "新增用电费用管理", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody ElectricitySettlementReq electricitySettlementReq) {
        return toAjax(electricitySettlementService.insert(electricitySettlementReq));
    }

    /**
     * 删除用电费用管理
     */
    @ApiOperation("删除用电费用管理")
    @SaCheckPermission("electricity:settlement:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @PostMapping("delete")
    @Log(title = "删除用电费用管理", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        electricitySettlementService.updateDeleteByIds(idList);
        return R.ok();
    }

    /**
     * 更新用电费用管理
     */
    @ApiOperation("更新用电费用管理")
    @SaCheckPermission("electricity:settlement:update")
    @PostMapping("/update")
    @Log(title = "更新用电费用管理", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody ElectricitySettlementReq electricitySettlementReq) {
        electricitySettlementService.updateById(electricitySettlementReq);
        return R.ok();
    }

    /**
     * 用电费用管理详情
     */
    @ApiOperation("用电费用管理详情")
//    @SaCheckPermission("dispatch:keepwatch:detail")
    @GetMapping("/{id}")
    public R<ElectricitySettlement> detail(@PathVariable("id") String id) {
        return R.ok(electricitySettlementService.selectDetailById(id));
    }

    /**
     * 用电费用管理列表
     */
    @ApiOperation("用电费用管理列表")
//    @SaCheckPermission("plan:drivage:page")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<ElectricitySettlementVo1>> page(ElectricitySettlementReq electricitySettlementReq, PageQuery pageQuery) {
        return R.ok(electricitySettlementService.selectPageList(electricitySettlementReq, pageQuery));
    }



    @ApiOperation("某年每队结算电度统计")
    @GetMapping("/getEachTeamKwh")
    @AutoSetMineCode
    public R<List<ElectricitySettlementVo>> getEachTeamKwh(ElectricitySettlementReq req){
        return R.ok(electricitySettlementService.getEachTeamKwh(req));
    }



    @ApiOperation("某年每月结算电度统计")
    @GetMapping("/getEachYearKwh")
    @AutoSetMineCode
    public R<List<ElectricitySettlementVo>> getEachYearKwh(ElectricitySettlementReq req){
        return R.ok(electricitySettlementService.getEachYearKwh(req));
    }





}
